﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using DataAccessLayer.Entity;
namespace DataAccessLayer.Adapter
{
    public class TinhThanhAdapter
    {
        //clsTinhThanh clTinhThanh = new clsTinhThanh();
        DataTable dt;
        clsKetNoiCSDL kn = new clsKetNoiCSDL();
       // SqlConnection con = new SqlConnection();
        //object kq;
        public DataTable LoadTinhThanh()
        {
            return dt = kn.LoadDL("tbTinhThanhLoadTinh");
        }
        public void ThemTinhThanh(clsTinh_ThanhPho clTinhThanh)
        {
            string sql = "tbTinhThanhThem";
            int Npa = 3;
            string []name=new string[Npa];
            object[] value = new object[Npa];
            name[0] = "@MaTinh"; value[0] = clTinhThanh.MaTinh;
            name[1] = "@TenTinh"; value[1] = clTinhThanh.TenTinh;
            name[2] = "@Active"; value[2] = clTinhThanh.Active;

            kn.UpdateDL(sql,name,value,Npa);
        }
        public void SuaTinhThanh(clsTinh_ThanhPho clTinhThanh)
        {
            string sql = "tbTinhThanhSua";
            int Npa = 2;
            string[] name = new string[Npa];
            object[] value = new object[Npa];
            name[0] = "@MaTinh"; value[0] = clTinhThanh.MaTinh;
            name[1] = "@TenTinh"; value[1] = clTinhThanh.TenTinh;

            kn.UpdateDL(sql,name,value,Npa);
        }
        public void XoaTinhThanh(clsTinh_ThanhPho clTinhThanh)
        {
            string sql = "tbTinhThanhXoa";
            int Npa = 1;
            string[] name = new string[Npa];
            object[] value = new object[Npa];
            name[0] = "@MaTinh"; value[0] = clTinhThanh.MaTinh;
            kn.UpdateDL(sql,name,value,Npa);
        }
        object kq;
        public object KiemTraMa(clsTinh_ThanhPho clsTinh)
        {
            string sql = "tbTinhThanh_KiemTraMa";
            int N = 1;
            string[] name = new string[N];
            object[] value = new object[N];
            name[0] = "@MaTinh"; value[0] = clsTinh.MaTinh;
            kq = kn.KTTrungMa(sql, name, value, N);
            return kq;
        }

        public object KiemTraTen(clsTinh_ThanhPho clsTinh)
        {
            string sql = "tbTinhThanh_KiemTraTen";
            int N = 1;
            string[] name = new string[N];
            object[] value = new object[N];
            name[0] = "@TenTinh"; value[0] = clsTinh.TenTinh;
            kq = kn.KTTrungMa(sql, name, value, N);
            return kq;
        }
    }
}
